<?php

abstract class DbAbstraction
{
    const DB_SESSION = 'DbSession';
    const DB_ABSTRACTION = 'DbAbstraction';
    
    protected $dbhelper;
    protected $session;
    public function __construct( IDbHelper $dbhelper )
    {
        $this->dbhelper = $dbhelper;
        $this->session = $this->createSession();
    }
    
    abstract protected function createSession();
    public function __call( $method, $args )
    {
        if( method_exists( $this, $method ) )
        {
            $reflection = new ReflectionMethod( self::DB_ABSTRACTION, $method );
            return $reflection->invokeArgs( $this, $args );
        }
        
        if( method_exists( $this->session, $method ) )
        {
            $reflection = new ReflectionMethod( self::DB_SESSION, $method );
            return $reflection->invokeArgs( $this->session, $args );
        }
        
        throw new Exception( 'No method \''.$method.'\' exists.' );
    }
}
